package com.example.admin.goodnews.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentTransaction;

import com.example.admin.goodnews.fragment.BaseFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * BaseFragment的适配器
 * Created by admin on 2016/10/19.
 */

public class BaseFragmentAdapter extends FragmentPagerAdapter {
    private List<String> tablist;
    private List<BaseFragment> fragments;

    public BaseFragmentAdapter(FragmentManager fm, List<String> tablist, List<BaseFragment> fragments) {
        super(fm);
        this.tablist = tablist;
        this.fragments = fragments;
    }

//    public void setFragments(List<BaseFragment> fragments) {
//        if (this.fragments != null) {
//            FragmentTransaction ft = fm.beginTransaction();
//            for (Fragment f : this.fragments) {
//                ft.remove(f);
//            }
//            ft.commit();
//            ft = null;
//            fm.executePendingTransactions();
//        }
//        this.fragments = fragments;
//        notifyDataSetChanged();
//    }

    @Override
    public BaseFragment getItem(int position) {
        return fragments.get(position);
    }

    @Override
    public int getCount() {
        return fragments.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return tablist.get(position);
    }
}
